<?php
namespace  Ekadmin\Controller;

use \Think\Controller;

use Think\Page;



class RewardlogController extends CommonController

{

        public  function index()

        {




            $where['uniacid'] = $this->uniacid;

            $obj = M('rewardlog');



            $param = I('get.');
            

            if($param['out_trade_no']){
            
                $where['out_trade_no'] =array('like','%'.$param['out_trade_no'].'%');
            
            }
            
            
            if($param['uid']){
                $where['uid'] = $param['uid'];
            }
            
            
            if($param['start'] && !$param['end']){
            
                $where['addtime'] = array('gt',strtotime($param['start']));
            
            }
            
            if(!$param['start'] && $param['end']){
            
                $where['addtime'] = array('lt',strtotime($param['end']));
            
            }
            
            if($param['start'] && $param['end']){
            
                $where['addtime'] = array('between',[strtotime($param['start']),strtotime($param['end'])]);
            
            }
            
            $count = $obj->where($where)->count();

            $page = new Page($count);
            
            $list = $obj->where($where)->limit($page->firstRow.','.$page->listRows)->order('id desc')->select();
            
            if($list){
                for($i=0;$i<count($list);$i++){
                    $rs=M("user")->find($list[$i]["uid"]);
                    $rt=M("xiaoqu")->where("uid=".$list[$i]["uid"])->find();
                    if($rt){
                        $list[$i]["name"]=$rt["tuan_name"];
                        $list[$i]["mobile"]=$rt["mobile"];
                    }else{
                        $list[$i]["name"]=$rs["name"];
                        $list[$i]["mobile"]=$rs["mobile"];
                    }
                    $list[$i]["acv"]=$rs["head"];
//                     switch($list[$i]["type"]){
//                         case 1:
//                             $list[$i]["type"]="<font color='green'>收入</font>";
//                             break;
//                         case 2:
//                             $list[$i]["type"]='<font color="red">支出</font>';
//                             break;
//                     }
                }
            }

            $this->assign('page',$page->show());
            
            $this->assign('count',$count);

            $this->assign('list',$list);

            
            $this->display();

        }

        

        /**
         *@批量删除记录 
         */
        public function del()

        {

            if(IS_POST){

                $param = I('id');

                if(is_array($param)){

                    $map['id'] = array('in',$param);

                }else{

                    $map['id'] = $param;

                }
                
                $map["uniacid"]=$this->uniacid;


                M('rewardlog')->where($map)->delete();

                ajax_return(0,'删除成功');

            }

        }


}